'use strict';
const requireEx=require('yi-require');

const handler =(req, res, next)=>{
    let id= req.params.id;
    req.mongo.collection('goodsType').find({_id:id}).next((e0,r0)=>{
        if(e0) return res.err.mongoError(e0);
        let storeId = r0.storeId;
        req.mongo.collection('goodsType').deleteOne({_id:id},(e1,r1)=>{
            if(e1) return res.err.mongoError(e1);
            req.mongo.collection('goodsType').updateMany({storeId:storeId,sort:{$gt:r0.sort}},{$inc:{sort:-1}},(e2,r2)=> {
                if (e2) return res.err.mongoError(e2);
                return res.reply({code:0,message:"删除成功"});
            });
        });
    });
};

module.exports={
    open:false,
    description: '删除商品类型',
    // handler:requireEx('yi-restful').d('goodsType',[])
    handler:handler
};
